"""
    Main module of GameServer. Based on Apache Thrift
    Package gameserver
    Project PyBaldaJ
    Provides:
        start() - starts the server
        theServer - Server object

"""
import logging.config

#logging support
import logging
import logging.config

#Thrift core library
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
#Generated Thrift package
from gameserver.service import GameService
#Request handler
from gameserver import handler

#Enable logging
logging.config.fileConfig('logger.conf')
logger = logging.getLogger('server')




def start(admin_id):
    handle = handler.Handler(admin = admin_id)
    processor = GameService.Processor(handle)
    transport = TSocket.TServerSocket(11111)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()

    theServer = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
    logger.info('Starting service...')
    theServer.serve()
